package controllers;

import iterfaces.Ships;

import java.util.ArrayList;

import ships.Destroyer;
import ships.Frigate;
import ships.Hunter;
import ships.Ship;
import ships.Submarine;
import ships.Transport;
import weapons.*;
import windows.GameConsole;

/**
 * @author 508461
 * @version 1.0
 * @created 24-mei-2012 12:47:48
 */
public class Map {

	public int height = 250000;
	public int width = 250000;
	public ArrayList<Ships> dObjects = new ArrayList<Ships>();
	public ArrayList<Ships> sObjects = new ArrayList<Ships>();
	public Waypoint m_Waypoint;
	public Missile m_Missile;
	public Torpedo m_Torpedo;
	public Chaff m_Chaff;
	public SoundBuoy m_SoundBuoy;
	public Frigate m_Frigate;
	public Submarine m_Submarine;
	public Transport m_Transport;
	public Hunter m_Hunter;
	public Destroyer m_Destroyer;
	public BulletCloud m_BulletCloud;

	private static Map map = null;
	
	protected Map() {
	      // Exists only to defeat instantiation.
	}
	
	public static Map getMap() {
	      if(map == null) {
	         map = new Map();
	      }	      
	      return map;
	}

	public void finalize() throws Throwable {

	}

	public void addWaypoint(){

	}

	public void deleteWaypoints(){
		
	}

	public Ship getShip(){
		return null;
	}

	public void selectShip(){

	}

	public void setHostility(){

	}

	public void showInformation(){

	}

	public void addDrawAbleShipInfo(String shipInfo){
		
		String info[] = shipInfo.split("\\|");		
		String name = info[0].split(":")[0];
		String team = info[0].split(":")[1];
		String image = info[0].split(":")[2];
		String boat = info[1].split(":")[0];		
		Point point = new Point(Double.parseDouble(info[1].split(":")[1].split(";")[0]), Double.parseDouble(info[1].split(":")[1].split(";")[1]));
	
		if (boat.toString().equals((String) Destroyer.class.toString())) {
		Destroyer ship = new Destroyer(point);
		ship.setImage(image);
		Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) Missile.class.toString())) {
			Missile ship = new Missile(point);
			ship.setImage('\\' + team +"\\bulletlarge.png");
			Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) Transport.class.toString())) {
			Transport ship = new Transport(point);
			ship.setImage("\\transport.png");
			Map.getMap().addDrawAbleObjectExternal(ship);
		} 
		if (boat.toString().equals((String) Frigate.class.toString())) {
		Frigate ship = new Frigate(point);
		ship.setImage('\\' + team +"\\land.png");
		Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) Hunter.class.toString())) {
		Hunter ship = new Hunter(point);
		ship.setImage('\\' + team +"\\land.png");
		Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) Submarine.class.toString())) {
		Submarine ship = new Submarine(point);
		ship.setImage('\\' + team +"\\sub.png");
		Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) Torpedo.class.toString())) {
			Torpedo ship = new Torpedo(point);
			ship.setImage('\\' + team +"\\bulletlarge.png");
			Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) Canonball.class.toString())) {
			Canonball ship = new Canonball(point);
			ship.setImage('\\' + team +"\\bulletsmall.png");
			Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) Chaff.class.toString())) {
			Chaff ship = new Chaff(point);
			ship.setImage('\\' + team +"\\bulletsmall.png");
			Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) BulletCloud.class.toString())) {
			BulletCloud ship = new BulletCloud(point);
			ship.setImage('\\' + team +"\\bulletsmall.png");
			Map.getMap().addDrawAbleObjectExternal(ship);
		}
		if (boat.toString().equals((String) SoundBuoy.class.toString())) {
			SoundBuoy ship = new SoundBuoy(point);
			ship.setImage('\\' + team +"\\bulletsmall.png");
			Map.getMap().addDrawAbleObjectExternal(ship);
		}
	}
	
	public void addDrawAbleObject(Ships o){
		dObjects.add(o);
	}

	public void addDrawAbleObjectExternal(Ships o){
		sObjects.add(o);
	}
}